/***************************************************************************
 *   Copyright (C) 2007 by Alexandre Masselot,,,   *
 *   alex@alex-laptop   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "utils/dbsequencefactoryfasta.h"
#include "utils/peptidemodifier.h"
#include "utils/peptidemsmsfactory.h"
#include "utils/aminoacidinstancerbasic.h"
#include "utils/enzymetrypsin.h"

#include <iostream>
#include <vector>

#define STRINGIFY(x) XSTRINGIFY(x)
#define XSTRINGIFY(x) #x

using namespace std;
using namespace bol;
int main(int argc, char **argv){

  DBSequenceFactoryFasta fasta;
  if(argc>1){
    fasta.openFile(argv[1]);
  }else{
    fasta.openFile(STRINGIFY(DATADIR) "/little.fasta");
  }

  AminoAcidInstancerBasic aainstancer;
  aainstancer.setMasses();

  //build a list of peptide out of the passed one and the modif set in the mofifier
  PeptideModifier peptmodifier;
  peptmodifier.addModif(new Modification("Cys_CAM C 57"), false);
  peptmodifier.addModif(new Modification("Oxidation HMW 16"), true);


  //the factory will be set up to produce peptide according to the given modifier (modifier cannot be modified thereafter)
  PeptideMSMSFactory factory;
  factory.setPeptideModifier(&peptmodifier);
  vector<Peptide> vmsmspept;

  Enzyme *enzyme=new EnzymeTrypsin();
  vector<Peptide> vcleavedpept;


  int nbentries=0;
  int nbpeptseq=0;
  int nbmsmspept=0;
  DBSequence entry;
  while(fasta.nextSequence(entry)){
/*      cout<<"AC="<<entry.ac()<<"\n";
      cout<<"description="<<entry.description()<<"\n";
      peptmodifier.printPeptide(cout, entry.sequence());
      cout<<endl;*/
      nbentries++;
      enzyme->cleave(*entry.sequence(), vcleavedpept);
      for(vector<Peptide>::iterator it=vcleavedpept.begin(); it<vcleavedpept.end(); it++){
//           peptmodifier.printPeptide(cout, &(*it));
//           cout<<"\t"<<it->getMass();
//           cout<<endl;
          nbpeptseq++;
          vmsmspept.clear();
          factory.createPeptides(*it, vmsmspept);
          nbmsmspept+=vmsmspept.size();
/*          for(vector<Peptide>::iterator it2=vmsmspept.begin(); it2<vmsmspept.end(); it2++){
              peptmodifier.printPeptide(cout, &(*it2));
              cout<<"\t"<<it2->getMass();
              cout<<endl;
          }*/
  
      }

  }
  cout<<"nb entries="<<nbentries<<endl;
  cout<<"nb pept seq="<<nbpeptseq<<endl;
  cout<<"nb msms pept"<<nbmsmspept<<endl;
  return 0;
}
